package com.bz.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bz.common.PageInfo;
import com.bz.common.UserConfig;
import com.bz.dao.CustomDao;
import com.bz.entity.CustomEntity;
import com.bz.entity.UserEntity;
import com.bz.service.ICustomService;

@Service
public class CustomeServiceImpl implements ICustomService {

    @Autowired
    private CustomDao customDao;

    @Override
    public PageInfo<CustomEntity> list(PageInfo page, LambdaQueryWrapper<CustomEntity> queryWrapper) {
        queryWrapper.orderByDesc(CustomEntity::getUpdateDate);
        return customDao.selectPage(page, queryWrapper);
    }

    @Override
    public void add(CustomEntity data) {
        UserEntity lu = UserConfig.getLoginUser();
        data.setCreateBy(lu.getUsername());
        data.setCreateDate(new Date());
        data.setUpdateBy(lu.getUsername());
        customDao.insert(data);
    }

    @Override
    public void update(CustomEntity data) {
        UserEntity lu = UserConfig.getLoginUser();
        data.setUpdateBy(lu.getUsername());
        customDao.updateById(data);
    }

    @Override
    public void delete(Long id) {
        customDao.deleteById(id);
    }

}
